package com.thoughtworks;

import java.util.ArrayList;
import java.util.List;

public class Render {
    String discountMethod;
    int finalPrice;
    int originalPrice;
    String[] ids;
    int[] numbers;
    String orderDetails = "============= 订餐明细 =============\n";
    List<Dish> dishes = DataProvider.getDishes();
    HelperFunctions helper = new HelperFunctions();

    public Render(String discountMethod, int finalPrice, int originalPrice, String[] ids, int[] numbers){
        this.discountMethod = discountMethod;
        this.finalPrice = finalPrice;
        this.originalPrice = originalPrice;
        this.ids = ids;
        this.numbers = numbers;
        for(int i=0;i<ids.length;i++) {
            this.orderDetails += helper.findItemName(ids[i]) + " x " + numbers[i] + " = "
                    + helper.findItemPrice(ids[i])*numbers[i] + "元\n";
        }
        this.orderDetails += "-----------------------------------\n";
    }

    public String renderOrderDetails(){
        if(discountMethod.equals("half")) {
            RenderHalf renderHalf = new RenderHalf(orderDetails,originalPrice, finalPrice, ids, numbers);
            orderDetails = renderHalf.renderApplication();
        }
        if(discountMethod.equals("thirty")) {
            RenderThirty renderThirty = new RenderThirty(orderDetails,originalPrice, finalPrice, ids, numbers);
            orderDetails = renderThirty.renderApplication();
        }
        if(discountMethod.equals("none")){
            orderDetails += "总计：" + finalPrice  + "元\n"
                    + "===================================";
        }
        return orderDetails;
    }

}
